from admin import Admin
from atm import ATM


class BankManager:
    def __init__(self):
        self.all_user_dict = {}  # 使用字典存储数据
        self.atm = ATM(self.all_user_dict)
        self.admin = Admin()     # 管理员开机欢迎界面

    def save_user(self):
        self.all_user_dict.update(self.atm.all_user)
        print("数据存盘成功！")

    def work(self):
        # 显示欢迎菜单
        self.admin.print_admin_view()
        # 管理员登录
        result = self.admin.check_option()
        if not result:
            while True:
                # 显示功能菜单界面
                self.admin.print_func_view()
                option = input("请输入您的操作：")
                if option not in ("1", "2", "3", "4", "5",
                                  "6", "7", "Q", "q"):
                    print("输入操作项有误，请仔细确认！")
                if option == "1":  # 开户
                    self.atm.create_user()
                elif option == "2":  # 查询
                    self.atm.search_user()
                elif option == "3":  # 取款
                    self.atm.get_money()
                elif option == "4":  # 存款
                    self.atm.save_money()
                elif option == "5":  # 转账
                    self.atm.transfer_money()
                elif option == "6":  # 锁定
                    self.atm.lock_card()
                elif option == "7":  # 解锁
                    self.atm.unlock_card()
                elif option.upper() == "Q":  # 退出
                    if not self.admin.check_option():
                        self.save_user()
                        print('退出系统！')
                        return -1


if __name__ == "__main__":
    bank_manager = BankManager()
    bank_manager.work()
